home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-06-16 | 3.2 KB | 145 lines | [TEXT/ttxt] |
- if ( gHasColorQuickDraw )
- limitR = (**GetGrayRgn()).rgnBBox;
- else
- limitR = screenBits.bounds;
-
- DragWindow( myWindow, theEvent->where, &limitR );
-
-
- ______
-
- /*
- IsPositionOK
-
- Description:
- Checks to make sure the passed global rectangle is completely contained within the
- gray region. Pass the window’s portRect in global coordinates.
-
- Notes:
- Depends on two regions, gSpareRgn1 and gSpareRgn2, having been allocated
- globally (using NewRgn).
-
- Your application might want to allow partially offscreen windows.
-
- Document windows are assumed to have title heights of 20 pixels. There are more
- dynamic ways of handling this, such as positioning the window way offscreen and
- checking its structure region.
- */
- Boolean IsPositionOK( Rect *globalR, Boolean isDocWindow )
- {
- Boolean isOK = false;
- Rect fullWindowR;
-
- #define kDocWindowHeight 20 // pixels
-
- // put the window rect into gSpareRgn1
- fullWindowR = *globalR;
- if ( isDocWindow )
- fullWindowR.top -= kDocWindowHeight;
- RectRgn( gSpareRgn1, &fullWindowR );
-
- // see if the window completely intersects the grayRgn
- SectRgn( GetGrayRgn(), gSpareRgn1, gSpareRgn2 );
- if ( EqualRgn( gSpareRgn1, gSpareRgn2 ) )
- isOK = true;
-
- return( isOK );
- }
-
-
- _________
-
- /*
- FindDeviceThatSupportsDepth
-
- Returns:
- The GDHandle for a device that supports the passed depth.
- Returns nil if no device found or no color quickdraw.
-
- Notes:
- Requires System 6.05 or later.
- */
- GDHandle FindDeviceThatSupportsDepth( short theDepth )
- {
- GDHandle aScreen;
-
- if ( !gHasColorQuickDraw )
- return( nil );
-
- // first check the main screen - it takes precedence
- aScreen = GetMainDevice();
- if ( DoesDeviceSupportDepth( aScreen, theDepth ) )
- return( aScreen );
-
- // step through all the screens
- aScreen = GetDeviceList();
-
- while ( aScreen )
- {
- if ( DoesDeviceSupportDepth( aScreen, theDepth ) )
- return( aScreen );
- aScreen = GetNextDevice( aScreen );
- }
-
- return( nil );
- }
-
- Boolean DoesDeviceSupportDepth( GDHandle theDevice, short theDepth )
- {
- if ( IsDeviceActive( theDevice ) &&
- HasDepth( theDevice, theDepth, 0/*whichFlags*/, 0 ) )
- return( true );
- else
- return( false );
- }
-
- Boolean IsDeviceActive( GDHandle theDevice )
- {
- if ( !theDevice )
- return( false );
-
- /*
- sometimes newly installed video cards show the main device
- as inactive. we’ll make an extra check for this case.
- */
- if ( theDevice == GetMainDevice() )
- return( true ); // main device is always active
-
- if ( TestDeviceAttribute( theDevice, screenDevice ) &&
- TestDeviceAttribute( theDevice, screenActive ) )
- return( true );
- else
- return( false );
- }
-
-
- _________
-
- short FindWindowDepth( WindowPtr myWindow )
- {
- Rect r;
- GDHandle theDevice;
- short theDepth;
- GrafPtr oldPort;
-
- if ( !gHasColorQuickDraw )
- return( 1 ); // 1-bit if no color quickdraw
-
- GetPort( &oldPort ); // save old port
- SetPort( myWindow );
-
- // get the window’s content rect in global coords
- r = myWindow->portRect;
- LocalToGlobal( (Point*) &r );
- LocalToGlobal( 1 + (Point*) &r );
-
- // find the deepest device intersecting the window
- theDevice = GetMaxDevice( &r );
- theDepth = theDevice ? (**(**theDevice).gdPMap).pixelSize : 1;
-
- // color table is at: (**(**theDevice).gdPMap).pmTable
-
- SetPort( oldPort ); // restore port
- return( theDepth );
- }
-